package com.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.action.SheetAction;
import com.exception.DBException;
import com.exception.StatisticException;
import com.util.HandleInfo;
import com.util.StateInfo;

public class SheetServlet extends HttpServlet
{

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		String sheet = request.getParameter("sheet");
		
		try
		{
			if ("top".equals(sheet))
			{
				new SheetAction().getTopTenSheet(request, response);
				return;
			}
			if ("in".equals(sheet))
			{
				new SheetAction().getIn(request, response);
				return;
			}
			if ("out".equals(sheet))
			{
				new SheetAction().getOut(request, response);
				return;
			}
			if ("tools".equals(sheet))
			{
				new SheetAction().getAllTools(request, response);
				return;
			}
			if ("users".equals(sheet))
			{
				new SheetAction().getAllUsers(request, response);
				return;
			}
			if(null==sheet || "".equals(sheet))
			{
				HandleInfo.handle(request, response, StateInfo.INNER_CONFIRM_FAIL);
			}
		}
		catch (DBException e)
		{
			HandleInfo.handle(request, response, e.getMessage());
		}
		catch (StatisticException e)
		{
			HandleInfo.handle(request, response, e.getMessage());
		}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		doGet(request, response);
	}

}
